import logging

import requests

logger = logging.getLogger('django')


def send_requests(method, body_type, req_url, payload, headers):
    method_map = {
        1: "get",
        2: "post",
        3: "put",
        4: "delete",
    }

    body_map = {
        1: {"data": payload},
        2: {"json": payload},
        3: {"data": payload},
        4: {"data": payload},
    }
    method = method_map[method]
    body_args = body_map[body_type]
    response = getattr(requests, method)(req_url, headers=headers, **body_args)
    logger.info("响应结果 =" + response.text)
    return response
